<template>
  <el-form ref="form" :model="data" :rules="rules" v-bind="$attrs">
    <slot></slot>
  </el-form>
</template>

<script>
export default {
  name: 'KForm',
  inheritAttrs: false,
  props: {
    data: Object,
    rules: Object
  },
  mounted () {
    this.$nextTick(() => {
      this.$el.onsubmit = (evt) => {
        evt.preventDefault()

        this.$refs['form'].validate((check) => {
          if (check) {
            this.$emit('submit', evt)
          } else {
            this.$emit('cancel', evt)
          }
        })
      }
    })
  },
  methods: {
  }
}
</script>

<style scoped>

</style>
